package com.runfast.waimai.web.controller.Driver_controller;

import com.runfast.waimai.dao.model.RunfastCreditlevel;
import com.runfast.waimai.service.RunfastCreditlevelService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/shopper/*")
public class ShopperRunfastCreditlevelContrllor  {
    @Resource
    RunfastCreditlevelService service; //骑手信用等级管理
    @PostMapping("updatecreditlevel")
    public @ResponseBody ModelMap  updatecreditlevel(RunfastCreditlevel creditlevel){
        ModelMap model=new ModelMap();
     if(creditlevel !=null){   service.updateByPrimaryKeySelective(creditlevel);
        model.put("success","修改成功");
     } else {
         model.put("msg","修改不成功");
     }

        return model;
    }
    @PostMapping("addcreditlevel")
    public @ResponseBody ModelMap  addcreditlevel(RunfastCreditlevel creditlevel){
        ModelMap model=new ModelMap();
        if(creditlevel !=null){
            service.insertSelective(creditlevel);
            model.put("success","添加成功");
        }else {
        model.put("success","添加不成功");}

        return model;
    }
    @PostMapping("delcreditlevel")
    public @ResponseBody ModelMap  delcreditlevel(Integer id){ //信誉等级管理id
        ModelMap model=new ModelMap();
        if(id !=null){   service.delete(id);
            model.put("success","删除成功");
        }else {
            model.put("msg","删除不成功");
        }

        return model;
    }
    @PostMapping("findcreditlevel")
    public @ResponseBody ModelMap  findcreditlevel(Integer id){ //信誉等级管理id
        ModelMap model=new ModelMap();
        if(id !=null){
            RunfastCreditlevel creditlevel=service.get(id);
            model.put("creditlevel",creditlevel);
        }else {
            model.put("msg","没有你要的数据");
        }


        return model;
    }
    @PostMapping("findcreditlevelAll")
    public @ResponseBody ModelMap  findcreditlevelAll(){ //信誉等级管理id
        ModelMap model=new ModelMap();
       List<RunfastCreditlevel> creditlevel=service.findAll();
        if(creditlevel!=null){
           model.put("creditlevel",creditlevel);
        } else {
            model.put("msg","没有你要的数据");

        }

        return model;
    }
    @PostMapping("findcreditlevelAndAgentid")//
    public @ResponseBody ModelMap  ifAndDir(Integer endgrade,String agentname){ //信誉等级管理id 和代理商ID 查询
        ModelMap model=new ModelMap();
        List<RunfastCreditlevel> creditlevel=service.findcreditlevelAndAgentid(endgrade,agentname);
        if(creditlevel!=null){
            model.put("creditlevel",creditlevel);
        } else {
            model.put("msg","没有你要的数据");

        }

        return model;
    }
}
